package com.example.program.demos.service;

import com.example.program.demos.mapper.ReportMapper;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ReportService {

    @Autowired
    ReportMapper reportMapper;

    private static final String TITLE_SALARY = "月建设项目农民工工资核算（公示）表";
    private static final String TITLE_ATTENDANCE = "月建设项目农民工考勤表";

    // 批量导出多个表
    public void exportMulitSheetsToSalary(ServletOutputStream outputStream, String[] groups, Map<String, Object> map) throws Exception {
        // 创建包含多个工作表的工作簿
        Workbook sheets = new XSSFWorkbook();
        String[] yearMonths = map.get("month").toString().split("-");
        // 查询公司名称和项目名称
        Map<String, Object> cProgram = reportMapper.getCprogramName(map);
        Date months = new SimpleDateFormat("yyyy-MM").parse(map.get("month").toString());
        map.replace("month", months);
        String[] headers = {
                "序号", "姓名", "身份证号", "银行卡号", "出勤天数", "约定工价", "基本工资", "绩效", "应发工资", "代扣代缴", "实发工资", "签字确认"
        };
        // 获取多个表的表名称（group）
        for (String group : groups) {
            Sheet sheet = sheets.createSheet(group + "组");
            // 根据group和公司项目名称月份获取后端数据
            map.put("group", group);
            List<Map<String, Object>> list = reportMapper.reportUserInf(map);
            // 创建标题
            addTitle(sheets, sheet, yearMonths, TITLE_SALARY, 11);
            // 创建公司信息
            addCompanyInf(sheets, sheet, cProgram, group, 11);

            //=====第二部分：表格列头
            addHeaderTable(sheets, sheet, headers);

            // =========================== 数据行
            CellStyle dataStyle = createDataStyle(sheets);
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> result = list.get(i);
                int rowNum = i + 3;
                Row row = sheet.createRow(rowNum);
                createStyledCell(row, 0, i + 1, dataStyle);
                createStyledCell(row, 1, result.get("name").toString(), dataStyle);
                createStyledCell(row, 2, result.get("password").toString(), dataStyle);
                createStyledCell(row, 3, result.get("bank_card").toString(), dataStyle);
                createStyledCell(row, 4, Double.parseDouble(result.get("attendance").toString()), dataStyle); // 出勤天数
                createStyledCell(row, 5, Integer.parseInt(result.get("work_price").toString()), dataStyle);  // 约定工价
                // 基本工资（约定工价*出勤天数）
//                createStyledCell(row, 6, "", dataStyle);
                Cell baseSalaryCell = row.createCell(6);
                baseSalaryCell.setCellType(CellType.FORMULA);
                baseSalaryCell.setCellFormula("E" + (rowNum + 1) + "*F" + (rowNum + 1));
                baseSalaryCell.setCellStyle(dataStyle);
                // 绩效
                Cell grossPayCell = row.createCell(7);
                grossPayCell.setCellType(CellType.FORMULA);
                grossPayCell.setCellFormula("I" + (rowNum + 1) + "-G" + (rowNum + 1));
                grossPayCell.setCellStyle(dataStyle);
                // 应发工资（基本工资+绩效）
//                createStyledCell(row, 8, "", dataStyle);

                createStyledCell(row, 8, Double.parseDouble(result.get("salary").toString()), dataStyle);
                // 代扣代缴（if(应发工资》5000则（应发工资-5000）*0.03，0)）
//                createStyledCell(row, 9, "", dataStyle);
                Cell remitMoneyCell = row.createCell(9);
                remitMoneyCell.setCellType(CellType.FORMULA);
                remitMoneyCell.setCellFormula("IF(I" + (rowNum + 1) + ">5000,(I" + (rowNum + 1) + "-5000)*0.03,0)");
                remitMoneyCell.setCellStyle(dataStyle);
                // 实发工资(应发工资-代扣代缴)
//                createStyledCell(row, 10, "", dataStyle);
                Cell netPayCell = row.createCell(10);
                netPayCell.setCellType(CellType.FORMULA);
                netPayCell.setCellFormula("I" + (rowNum + 1) + "-J" + (rowNum + 1));
                netPayCell.setCellStyle(dataStyle);
                createStyledCell(row, 11, "", dataStyle);
            }

            //====================合计行
            int lastRowNum = list.size() + 3;
            Row totalRow = sheet.createRow(lastRowNum);
//            sheet.addMergedRegion(new CellRangeAddress(lastRowNum, lastRowNum, 0,3));
            createStyledCell(totalRow, 0, "合计", dataStyle);
            createStyledCell(totalRow, 1, "", dataStyle);
            createStyledCell(totalRow, 2, "", dataStyle);
            createStyledCell(totalRow, 3, "", dataStyle);
            createStyledCell(totalRow, 4, "", dataStyle);
            createStyledCell(totalRow, 5, "", dataStyle);
//          基本工资合计  createStyledCell(totalRow, 6, "", dataStyle);
            Cell totalBaseCell = totalRow.createCell(6);
            totalBaseCell.setCellType(CellType.FORMULA);
            totalBaseCell.setCellFormula("SUM(G4:G" + (lastRowNum) + ")");
            totalBaseCell.setCellStyle(dataStyle);
            // 绩效合计           createStyledCell(totalRow, 7, "", dataStyle);
            Cell totalPerformanceCell = totalRow.createCell(7);
            totalPerformanceCell.setCellType(CellType.FORMULA);
            totalPerformanceCell.setCellFormula("SUM(H4:H" + (lastRowNum) + ")");
            totalPerformanceCell.setCellStyle(dataStyle);
//          应发工资合计  createStyledCell(totalRow, 8, "", dataStyle);
            Cell totalGrossCell = totalRow.createCell(8);
            totalGrossCell.setCellType(CellType.FORMULA);
            totalGrossCell.setCellFormula("SUM(I4:I" + (lastRowNum) + ")");
            totalGrossCell.setCellStyle(dataStyle);
//          代扣代缴 createStyledCell(totalRow, 9, "", dataStyle);remitMoney
            Cell totalRemitCell = totalRow.createCell(9);
            totalRemitCell.setCellType(CellType.FORMULA);
            totalRemitCell.setCellFormula("SUM(J4:J" + (lastRowNum) + ")");
            totalRemitCell.setCellStyle(dataStyle);
//          实发工资合计  createStyledCell(totalRow, 10, "", dataStyle);
            Cell totalNetCell = totalRow.createCell(10);
            totalNetCell.setCellType(CellType.FORMULA);
            totalNetCell.setCellFormula("SUM(K4:K" + (lastRowNum) + ")");
            totalNetCell.setCellStyle(dataStyle);
            createStyledCell(totalRow, 11, "", dataStyle);

            //===================签字行
            Row signRow = sheet.createRow(lastRowNum + 1);
            signRow.setHeightInPoints(20);
            Cell signCell = signRow.createCell(0);
            signCell.setCellValue("制表人签名：                班组负责人签名：                项目负责人签名（项目部盖章）：                     制表时间：    年  月");
            sheet.addMergedRegion(new CellRangeAddress(lastRowNum + 1, lastRowNum + 1, 0, 11));

            //==== 自动调整列宽
            for (int i = 0; i < 12; i++) {
                sheet.autoSizeColumn(i);
                sheet.setColumnWidth(i, 10 * 256);
            }

            // 身份证和银行卡号列加宽
            sheet.setColumnWidth(2, 20 * 256);
            sheet.setColumnWidth(3, 20 * 256);

        }
        sheets.write(outputStream);
        sheets.close();
    }


    // 合并导出表
    public void exportMergeSalary(ServletOutputStream outputStream, String reGroup, Map<String, Object> map) throws Exception {
        // 创建包含多个工作表的工作簿
        Workbook sheets = new XSSFWorkbook();
        String[] yearMonths = map.get("month").toString().split("-");
        // 查询公司名称和项目名称
        Map<String, Object> cProgram = reportMapper.getCprogramName(map);
        Date months = new SimpleDateFormat("yyyy-MM").parse(map.get("month").toString());
        map.replace("month", months);
        String[] headers = {
                "序号", "姓名", "身份证号", "银行卡号", "出勤天数", "约定工价", "基本工资", "绩效", "应发工资", "代扣代缴", "实发工资", "签字确认"
        };
        // 根据多个组查询数据
        List<Map<String, Object>> list = reportMapper.reportUserAttendance(map);

        Sheet sheet = sheets.createSheet(reGroup + "组");
        // 根据group和公司项目名称月份获取后端数据
        // 创建标题
        addTitle(sheets, sheet, yearMonths, TITLE_SALARY, 11);
        // 创建公司信息
        addCompanyInf(sheets, sheet, cProgram, reGroup, 11);

        //=====第二部分：表格列头
        addHeaderTable(sheets, sheet, headers);

        // =========================== 数据行
        CellStyle dataStyle = createDataStyle(sheets);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> result = list.get(i);
            int rowNum = i + 3;
            Row row = sheet.createRow(rowNum);
            createStyledCell(row, 0, i + 1, dataStyle);
            createStyledCell(row, 1, result.get("name").toString(), dataStyle);
            createStyledCell(row, 2, result.get("password").toString(), dataStyle);
            createStyledCell(row, 3, result.get("bank_card").toString(), dataStyle);
            createStyledCell(row, 4, Double.parseDouble(result.get("attendance").toString()), dataStyle); // 出勤天数
            createStyledCell(row, 5, Integer.parseInt(result.get("work_price").toString()), dataStyle);  // 约定工价
            // 基本工资（约定工价*出勤天数）
//                createStyledCell(row, 6, "", dataStyle);
            Cell baseSalaryCell = row.createCell(6);
            baseSalaryCell.setCellType(CellType.FORMULA);
            baseSalaryCell.setCellFormula("E" + (rowNum + 1) + "*F" + (rowNum + 1));
            baseSalaryCell.setCellStyle(dataStyle);
            // 绩效
            Cell grossPayCell = row.createCell(7);
            grossPayCell.setCellType(CellType.FORMULA);
            grossPayCell.setCellFormula("I" + (rowNum + 1) + "-G" + (rowNum + 1));
            grossPayCell.setCellStyle(dataStyle);
            // 应发工资（基本工资+绩效）
//                createStyledCell(row, 8, "", dataStyle);

            createStyledCell(row, 8, Double.parseDouble(result.get("salary").toString()), dataStyle);
            // 代扣代缴（if(应发工资》5000则（应发工资-5000）*0.03，0)）
//                createStyledCell(row, 9, "", dataStyle);
            Cell remitMoneyCell = row.createCell(9);
            remitMoneyCell.setCellType(CellType.FORMULA);
            remitMoneyCell.setCellFormula("IF(I" + (rowNum + 1) + ">5000,(I" + (rowNum + 1) + "-5000)*0.03,0)");
            remitMoneyCell.setCellStyle(dataStyle);
            // 实发工资(应发工资-代扣代缴)
//                createStyledCell(row, 10, "", dataStyle);
            Cell netPayCell = row.createCell(10);
            netPayCell.setCellType(CellType.FORMULA);
            netPayCell.setCellFormula("I" + (rowNum + 1) + "-J" + (rowNum + 1));
            netPayCell.setCellStyle(dataStyle);
            createStyledCell(row, 11, "", dataStyle);
        }

        //====================合计行
        int lastRowNum = list.size() + 3;
        Row totalRow = sheet.createRow(lastRowNum);
//            sheet.addMergedRegion(new CellRangeAddress(lastRowNum, lastRowNum, 0,3));
        createStyledCell(totalRow, 0, "合计", dataStyle);
        createStyledCell(totalRow, 1, "", dataStyle);
        createStyledCell(totalRow, 2, "", dataStyle);
        createStyledCell(totalRow, 3, "", dataStyle);
        createStyledCell(totalRow, 4, "", dataStyle);
        createStyledCell(totalRow, 5, "", dataStyle);
//          基本工资合计  createStyledCell(totalRow, 6, "", dataStyle);
        Cell totalBaseCell = totalRow.createCell(6);
        totalBaseCell.setCellType(CellType.FORMULA);
        totalBaseCell.setCellFormula("SUM(G4:G" + (lastRowNum) + ")");
        totalBaseCell.setCellStyle(dataStyle);
        // 绩效合计           createStyledCell(totalRow, 7, "", dataStyle);
        Cell totalPerformanceCell = totalRow.createCell(7);
        totalPerformanceCell.setCellType(CellType.FORMULA);
        totalPerformanceCell.setCellFormula("SUM(H4:H" + (lastRowNum) + ")");
        totalPerformanceCell.setCellStyle(dataStyle);
//          应发工资合计  createStyledCell(totalRow, 8, "", dataStyle);
        Cell totalGrossCell = totalRow.createCell(8);
        totalGrossCell.setCellType(CellType.FORMULA);
        totalGrossCell.setCellFormula("SUM(I4:I" + (lastRowNum) + ")");
        totalGrossCell.setCellStyle(dataStyle);
//          代扣代缴 createStyledCell(totalRow, 9, "", dataStyle);remitMoney
        Cell totalRemitCell = totalRow.createCell(9);
        totalRemitCell.setCellType(CellType.FORMULA);
        totalRemitCell.setCellFormula("SUM(J4:J" + (lastRowNum) + ")");
        totalRemitCell.setCellStyle(dataStyle);
//          实发工资合计  createStyledCell(totalRow, 10, "", dataStyle);
        Cell totalNetCell = totalRow.createCell(10);
        totalNetCell.setCellType(CellType.FORMULA);
        totalNetCell.setCellFormula("SUM(K4:K" + (lastRowNum) + ")");
        totalNetCell.setCellStyle(dataStyle);
        createStyledCell(totalRow, 11, "", dataStyle);

        //===================签字行
        Row signRow = sheet.createRow(lastRowNum + 1);
        signRow.setHeightInPoints(20);
        Cell signCell = signRow.createCell(0);
        signCell.setCellValue("制表人签名：                班组负责人签名：                项目负责人签名（项目部盖章）：                     制表时间：    年  月");
        sheet.addMergedRegion(new CellRangeAddress(lastRowNum + 1, lastRowNum + 1, 0, 11));

        //==== 自动调整列宽
        for (int i = 0; i < 12; i++) {
            sheet.autoSizeColumn(i);
            sheet.setColumnWidth(i, 10 * 256);
        }

        // 身份证和银行卡号列加宽
        sheet.setColumnWidth(2, 20 * 256);
        sheet.setColumnWidth(3, 20 * 256);


        sheets.write(outputStream);
        sheets.close();
    }


    public void exportBatchAttendance(ServletOutputStream outputStream, String[] groups, Map<String, Object> map) throws Exception {
        // 创建包含多个工作表的工作簿
        Workbook sheets = new XSSFWorkbook();
        String[] yearMonths = map.get("month").toString().split("-");
        int day = getDaysInMonth(map.get("month").toString());
        // 查询公司名称和项目名称
        Map<String, Object> cProgram = reportMapper.getCprogramName(map);
        Date months = new SimpleDateFormat("yyyy-MM").parse(map.get("month").toString());
        map.replace("month", months);
        String[] headers = new String[day + 4];
        headers[0] = "序号";
        headers[1] = "姓名";
        for (int i = 0; i < day; i++) {
            headers[i + 2] = String.valueOf((i + 1));
        }
        headers[day + 2] = "合计";
        headers[day + 3] = "签字确认";
        // 获取多个表的表名称（group）
        for (String group : groups) {
            Sheet sheet = sheets.createSheet(group + "组");
            // 根据group和公司项目名称月份获取后端数据
            map.put("group", group);
            List<Map<String, Object>> list = reportMapper.reportBatchAttendance(map);
            // 创建标题
            addTitle(sheets, sheet, yearMonths, TITLE_ATTENDANCE, day + 3);
            // 创建公司信息
            addCompanyInf(sheets, sheet, cProgram, group, day + 3);

            //=====第二部分：表格列头
            addHeaderTable(sheets, sheet, headers);

            // =========================== 数据行
            CellStyle dataStyle = createDataStyle(sheets);
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> result = list.get(i);
                int rowNum = i + 3;
                Row row = sheet.createRow(rowNum);
                createStyledCell(row, 0, i + 1, dataStyle);
                createStyledCell(row, 1, result.get("name").toString(), dataStyle);
                for (int j = 0; j < day; j++) {
                    int d = Integer.parseInt(result.get("_" + (j + 1)).toString());
                    createStyledCell(row, j + 2, d == 0 ? "" : d == 1 ? "√" : "×", dataStyle);
                }
                createStyledCell(row, day + 2, Double.parseDouble(result.get("attendance").toString()), dataStyle);
                createStyledCell(row, day + 3, "", dataStyle);
            }
            //===================签字行
            int lastRowNum = list.size() + 3;
            Row signRow = sheet.createRow(lastRowNum);
            signRow.setHeightInPoints(20);
            Cell signCell = signRow.createCell(0);
            signCell.setCellValue("制表人签名：           班组负责人签名：           项目负责人签名（项目部盖章）：                 制表时间：    年  月");
            sheet.addMergedRegion(new CellRangeAddress(lastRowNum, lastRowNum, 0, day + 3));

            //==== 自动调整列宽
            for (int i = 0; i < (day + 3); i++) {
                sheet.autoSizeColumn(i);

            }
            sheet.setColumnWidth(1, 10 * 256);
        }
        sheets.write(outputStream);
        sheets.close();
    }


    public void exportMergeAttendance(ServletOutputStream outputStream, String reGroup, Map<String, Object> map) throws Exception {
        // 创建包含多个工作表的工作簿
        Workbook sheets = new XSSFWorkbook();
        String[] yearMonths = map.get("month").toString().split("-");
        int day = getDaysInMonth(map.get("month").toString());
        // 查询公司名称和项目名称
        Map<String, Object> cProgram = reportMapper.getCprogramName(map);
        Date months = new SimpleDateFormat("yyyy-MM").parse(map.get("month").toString());
        map.replace("month", months);
        String[] headers = new String[day + 4];
        headers[0] = "序号";
        headers[1] = "姓名";
        for (int i = 0; i < day; i++) {
            headers[i + 2] = String.valueOf((i + 1));
        }
        headers[day + 2] = "合计";
        headers[day + 3] = "签字确认";
        // 获取多个表的表名称（group）
        Sheet sheet = sheets.createSheet(reGroup + "组");
        // 根据group和公司项目名称月份获取后端数据
        List<Map<String, Object>> list = reportMapper.reportMergeAttendance(map);
        // 创建标题
        addTitle(sheets, sheet, yearMonths, TITLE_ATTENDANCE, day + 3);
        // 创建公司信息
        addCompanyInf(sheets, sheet, cProgram, reGroup, day + 3);

        //=====第二部分：表格列头
        addHeaderTable(sheets, sheet, headers);

        // =========================== 数据行
        CellStyle dataStyle = createDataStyle(sheets);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> result = list.get(i);
            int rowNum = i + 3;
            Row row = sheet.createRow(rowNum);
            createStyledCell(row, 0, i + 1, dataStyle);
            createStyledCell(row, 1, result.get("name").toString(), dataStyle);
            for (int j = 0; j < day; j++) {
                int d = Integer.parseInt(result.get("_" + (j + 1)).toString());
                createStyledCell(row, j + 2, d == 0 ? "" : d == 1 ? "√" : "×", dataStyle);
            }
            createStyledCell(row, day + 2, Double.parseDouble(result.get("attendance").toString()), dataStyle);
            createStyledCell(row, day + 3, "", dataStyle);
        }
        //===================签字行
        int lastRowNum = list.size() + 3;
        Row signRow = sheet.createRow(lastRowNum);
        signRow.setHeightInPoints(20);
        Cell signCell = signRow.createCell(0);
        signCell.setCellValue("制表人签名：           班组负责人签名：           项目负责人签名（项目部盖章）：                 制表时间：    年  月");
        sheet.addMergedRegion(new CellRangeAddress(lastRowNum, lastRowNum, 0, day + 3));

        //==== 自动调整列宽
        for (int i = 0; i < (day + 3); i++) {
            sheet.autoSizeColumn(i);

        }
        sheet.setColumnWidth(1, 10 * 256);
        sheets.write(outputStream);
        sheets.close();
    }


    // 设置标题
    private void addTitle(Workbook sheets, Sheet sheet, String[] yearMonths, String titleName, int lastCol) {
        String year = yearMonths[0];
        String month = yearMonths[1];
        sheet.setDefaultRowHeightInPoints(20);
        Row titleRow = sheet.createRow(0);
        titleRow.setHeightInPoints(25);
        Cell titleCell = titleRow.createCell(0);
        titleCell.setCellValue(year + "年" + month + titleName);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, lastCol)); // 合并单元格
        // 设置公司信息样式
        CellStyle titleStyle = sheets.createCellStyle();
        Font titleFont = sheets.createFont();
        titleFont.setBold(true);
        titleFont.setFontHeightInPoints((short) 14);
        titleStyle.setFont(titleFont);
        titleStyle.setAlignment(HorizontalAlignment.CENTER);
        titleCell.setCellStyle(titleStyle);

    }

    // 设置公司信息
    private void addCompanyInf(Workbook sheets, Sheet sheet, Map<String, Object> cProgram, String group, int lastCol) {
        Row companyRow = sheet.createRow(1);
        companyRow.setHeightInPoints(25);
        Cell companyCell = companyRow.createCell(0);
        companyCell.setCellValue("公司名称：" + cProgram.get("company") + "    项目名称：" + cProgram.get("programm") + "     班组名称：" + group + "班组");
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, lastCol));

        CellStyle companyStyle = sheets.createCellStyle();
        Font companyFont = sheets.createFont();
        companyFont.setBold(true);
        companyFont.setFontHeightInPoints((short) 12);
        companyStyle.setFont(companyFont);
        companyStyle.setAlignment(HorizontalAlignment.CENTER);
        companyCell.setCellStyle(companyStyle);

    }

    // 设置表头
    private void addHeaderTable(Workbook sheets, Sheet sheet, String[] headers) {
        Row headerRow = sheet.createRow(2);
        headerRow.setHeightInPoints(20);
        // 设置列头样式
        CellStyle headerStyle = sheets.createCellStyle();
//        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); // 设置单元格的背景前景色为25%灰度的灰色
//        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);  // 设置用前景色完全填充单元格
        setBorderStyle(headerStyle);
        Font headerFont = sheets.createFont();
        headerFont.setBold(true);
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER);
        // 填充列头
        for (int i = 0; i < headers.length; i++) {
            Cell cell = headerRow.createCell(i);
            cell.setCellValue(headers[i]);
            cell.setCellStyle(headerStyle);
        }
    }

    // 设置数据样式
    private CellStyle createDataStyle(Workbook sheets) {
        CellStyle dataStyle = sheets.createCellStyle();
        setBorderStyle(dataStyle);
        return dataStyle;
    }

    private void setBorderStyle(CellStyle style) {
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderTop(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
    }

    private void createStyledCell(Row row, int column, Object value, CellStyle style) {
        Cell cell = row.createCell(column);
        if (value instanceof String) {
            cell.setCellValue((String) value);
        } else if (value instanceof Integer) {
            cell.setCellValue((Integer) value);
        } else if (value instanceof Boolean) {
            cell.setCellValue((Boolean) value);
        } else if (value instanceof Double) {
            cell.setCellValue((Double) value);
        }
        cell.setCellStyle(style);
    }

    public int getDaysInMonth(String yearMonth) {
        String[] parts = yearMonth.split("-");
        int year = Integer.parseInt(parts[0]);
        int month = Integer.parseInt(parts[1]);
        return YearMonth.of(year, month).lengthOfMonth();
    }


}

